//
// 检测括号匹配
// 难度：中等
//

#include <vector>
#include <iostream>
#include "GStack.h"

std::vector<std::pair<char, char>> bracketPairs = {{'(', ')'},
                                                   {'[', ']'},
                                                   {'{', '}'}};

// 对括号类型进行标记
enum BracketStyleEnum {
    LeftBracket,
    RightBracket,
};

std::pair<int, BracketStyleEnum> getBracketStyle(char bracket) {
    BracketStyleEnum bracketStyle;
    int index = 0;
    for (auto bracketPair: bracketPairs) {
        if (bracketPair.first == bracket) {
            bracketStyle = LeftBracket;
            break;
        } else if (bracketPair.second == bracket) {
            bracketStyle = RightBracket;
            break;
        }
        index++;
    }
    // 返回括号的位置和括号的类型
    return {index, bracketStyle};
}

[[maybe_unused]] void bracketMatch() {

    GStack<char> bracketStack;

    std::string bracketStr;
    std::cin >> bracketStr;

    for (char curBracket: bracketStr) {
        int bracketIndex = getBracketStyle(curBracket).first;
        BracketStyleEnum bracketStyle = getBracketStyle(curBracket).second;
        // 左括号入栈
        if (bracketStyle == LeftBracket) {
            bracketStack.push(curBracket);
        } // 右括号出栈
        else if (bracketStyle == RightBracket) {
            // 右括号与左括号不匹配，则括号匹配失败
            if (bracketStack.top() != bracketPairs[bracketIndex].first) {
                std::cout << "no";
                return;
            } else {
                bracketStack.pop();
            }
        }
    }

    // 栈为空，则括号匹配成功
    if (bracketStack.empty()) {
        std::cout << "yes";
    } else {
        std::cout << "no";
    }
}
